package cn.iotab.iotkit.transport.api.common.queue;

import cn.iotab.iotkit.queue.queue.QueueClientSetting;
import cn.iotab.iotkit.queue.queue.provider.kafka.KafkaSetting;
import cn.iotab.iotkit.queue.rpc.factory.QueueRpcSetting;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Collections;
import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class TransportQueueConfig {

    // for kafka
    private String bootstrapServer;
    private long kafkaAdminTimeout = 3000;


    // for rpc
    private int rpcMaxPendingRequests = 100;
    private int rpcMaxRequestsTimeout = 30000;
    private long rpcPollInterval = 1000L;
    private int rpcResponseTemplateMaxCallbackThreads = 1;

    public KafkaSetting getKafkaSetting(){
        KafkaSetting kafkaSetting = new KafkaSetting();
        kafkaSetting.setServers(bootstrapServer);
        kafkaSetting.setAcks("1");
        kafkaSetting.setTimeout(kafkaAdminTimeout);
        return kafkaSetting;
    }

    public Map<String, String> getTopicSetting(){
        return Collections.emptyMap();
    }

    public QueueClientSetting getClientSetting(){
        QueueClientSetting clientSetting = new QueueClientSetting();
        clientSetting.setClientId(null);
        //clientSetting.setTopic(topic);
        //clientSetting.setGroupId(groupId);
        return clientSetting;
    }

    public QueueRpcSetting getRpcSetting(){
        QueueRpcSetting rpcSetting = new QueueRpcSetting();
        //rpcSetting.setRpcChannelId(rpcChannelId);
        rpcSetting.setMaxPendingRequests(rpcMaxPendingRequests);
        rpcSetting.setMaxRequestsTimeout(rpcMaxRequestsTimeout);
        rpcSetting.setPollInterval(rpcPollInterval);
        rpcSetting.setResponseTemplateMaxCallbackThreads(rpcResponseTemplateMaxCallbackThreads);
        return rpcSetting;
    }

}
